from typing import List


class Solution:
    def sumOddLengthSubarrays(self, arr: List[int]) -> int:
        prefix = [0] * (len(arr) + 1)
        for i in range(len(arr)):
            prefix[i + 1] = prefix[i] + arr[i]

        ans = 0
        for start in range(len(arr)):
            
            length = 1
            while start + length <= len(arr):
                end = start + length - 1
                ans += prefix[end + 1] - prefix[start]
                length += 2
            start += 1
        return ans